home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / v10n22.arc / ITRIG.ASM < prev    next >
Assembly Source File  |  1991-12-08  |  7KB  |  168 lines

  1.         title   ITRIG - Integer Trig Lookup
  2.         page    55,132
  3.  
  4. ; ITRIG.ASM -- Integer Trig Lookup Routines
  5. ; Copyright (C) 1991 Ray Duncan
  6. ;
  7. _DATA   segment word public 'DATA'
  8.  
  9. table   dw      0                       ; 0 degrees
  10.         dw      175                     ; 1 
  11.         dw      349                     ; 2
  12.         dw      523                     ; 3
  13.         dw      698                     ; 4
  14.         dw      872                     ; 5
  15.         dw      1045                    ; 6
  16.         dw      1219                    ; 7
  17.         dw      1392                    ; 8
  18.         dw      1564                    ; 9
  19.         dw      1736                    ; 10
  20.         dw      1908                    ; 11
  21.         dw      2079                    ; 12
  22.         dw      2250                    ; 13
  23.         dw      2419                    ; 14
  24.         dw      2588                    ; 15
  25.         dw      2756                    ; 16
  26.         dw      2924                    ; 17
  27.         dw      3090                    ; 18
  28.         dw      3256                    ; 19
  29.         dw      3420                    ; 20
  30.         dw      3584                    ; 21
  31.         dw      3746                    ; 22
  32.         dw      3907                    ; 23
  33.         dw      4067                    ; 24
  34.         dw      4226                    ; 25
  35.         dw      4384                    ; 26
  36.         dw      4540                    ; 27
  37.         dw      4695                    ; 28
  38.         dw      4848                    ; 29
  39.         dw      5000                    ; 30
  40.         dw      5150                    ; 31
  41.         dw      5299                    ; 32
  42.         dw      5446                    ; 33
  43.         dw      5592                    ; 34
  44.         dw      5736                    ; 35
  45.         dw      5878                    ; 36
  46.         dw      6018                    ; 37
  47.         dw      6157                    ; 38
  48.         dw      6293                    ; 39
  49.         dw      6428                    ; 40
  50.         dw      6561                    ; 41
  51.         dw      6691                    ; 42
  52.         dw      6820                    ; 43
  53.         dw      6947                    ; 44
  54.         dw      7071                    ; 45
  55.         dw      7193                    ; 46
  56.         dw      7314                    ; 47
  57.         dw      7431                    ; 48
  58.         dw      7547                    ; 49
  59.         dw      7660                    ; 50
  60.         dw      7771                    ; 51
  61.         dw      7880                    ; 52
  62.         dw      7986                    ; 53
  63.         dw      8090                    ; 54
  64.         dw      8192                    ; 55
  65.         dw      8290                    ; 56
  66.         dw      8387                    ; 57
  67.         dw      8480                    ; 58
  68.         dw      8572                    ; 59
  69.         dw      8660                    ; 60
  70.         dw      8746                    ; 61
  71.         dw      8829                    ; 62
  72.         dw      8910                    ; 63
  73.         dw      8988                    ; 64
  74.         dw      9063                    ; 65
  75.         dw      9135                    ; 66
  76.         dw      9205                    ; 67
  77.         dw      9272                    ; 68
  78.         dw      9336                    ; 69
  79.         dw      9397                    ; 70
  80.         dw      9455                    ; 71
  81.         dw      9511                    ; 72
  82.         dw      9563                    ; 73
  83.         dw      9613                    ; 74
  84.         dw      9659                    ; 75
  85.         dw      9703                    ; 76
  86.         dw      9744                    ; 77
  87.         dw      9781                    ; 78
  88.         dw      9816                    ; 79
  89.         dw      9848                    ; 80
  90.         dw      9877                    ; 81
  91.         dw      9903                    ; 82
  92.         dw      9925                    ; 83
  93.         dw      9945                    ; 84
  94.         dw      9962                    ; 85
  95.         dw      9976                    ; 86
  96.         dw      9986                    ; 87
  97.         dw      9994                    ; 88
  98.         dw      9998                    ; 89
  99.         dw      10000                   ; 90 degrees
  100.  
  101. _DATA   ends
  102.  
  103. _TEXT   segment word public 'CODE'
  104.  
  105.         assume  cs:_TEXT,ds:_DATA
  106.  
  107. ;
  108. ; TRIG:         Worker routine for SINE and COSINE
  109. ; Call with:    AX = degrees 0-180
  110. ; Returns:      AX = function value
  111. ; Destroys:     BX
  112. ;
  113. trig    proc    near
  114.         mov     bx,ax                   ; bx <- degrees
  115.         cmp     bx,90                   ; degrees = 90-180?
  116.         jle     trig1                   ; no, jump
  117.         sub     bx,180                  ; yes, reduce the angle
  118.         neg     bx                      ; to range 0-90
  119. trig1:  sal     bx,1                    ; bx <- degrees * 2
  120.         mov     ax,[bx+table]           ; extract function value
  121.         ret                             ; back to caller
  122. trig    endp
  123.  
  124. ;
  125. ; COSINE        Return cosine of angle
  126. ; Call with:    AX = degrees 0-359
  127. ; Returns:      AX = cosine of angle * 10000
  128. ; Destroys:     Nothing
  129. ;
  130.         public  cosine
  131. cosine  proc    near                    ; add 90 degrees to angle and
  132.         add     ax,90                   ; fall through to sine routine
  133. cosine  endp
  134.  
  135. ;
  136. ; SINE          Return sine of angle
  137. ; Call with:    AX = degrees 0-359
  138. ; Returns:      AX = sine of angle * 10000
  139. ; Destroys:     Nothing
  140. ;
  141.         public  sine
  142. sine    proc    near
  143.         push    bx                      ; save registers
  144.         push    dx
  145.         cwd                             ; degrees -> double precision
  146.         mov     bx,360                  ; reduce angle to 0-359 degrees
  147.         idiv    bx
  148.         mov     ax,dx                   ; AX <- reduced angle
  149.         or      ax,ax                   ; is angle negative?
  150.         jns     sine2                   ; no, jump
  151.         add     ax,360                  ; yes, make it positive
  152. sine2:  cmp     ax,180                  ; is angle >180 degrees?
  153.         jle     sine3                   ; no, jump
  154.         sub     ax,180                  ; yes, reduce to 0-179 degrees
  155.         call    trig                    ; and look up function value
  156.         neg     ax                      ; negate result and return
  157.         jmp     sine4
  158. sine3:  call    trig                    ; angle was <= 180
  159. sine4:  pop     dx                      ; restore registers
  160.         pop     bx
  161.         ret                             ; return to caller
  162. sine    endp
  163.  
  164. _TEXT   ends
  165.  
  166.         end     
  167.  
  168.